using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Ivory;
using CrystalCore;

namespace Barva
{
    public static partial class GraphicsParams
    {
        public static bool DrawWireFrame = false;
        public static bool EnableCulling = false;
        public static Color BufferColour = new Color(40,0,60);
    }

    public class Launcher : Microsoft.Xna.Framework.Game
    {
        private ScreenManager Manager;

        public Launcher()
        {
            Content.RootDirectory = "Content";
            Manager = new ScreenManager(this, "data/config.cfg");
        }

        protected override void Initialize()
        {
            ObjectHolder.GameObject = this;
            Manager.SetMainMenu(new MainMenu(this));

            Manager.AddGameScreen(RenderTest01.Key, new RenderTest01(this));
            Manager.AddGameScreen(RenderTest02.Key, new RenderTest02(this));
            Manager.AddGameScreen(SelectionTest.Key, new SelectionTest(this));
            Manager.AddGameScreen(PathingTest.Key, new PathingTest(this));
            Manager.AddGameScreen(LevelTest.Key, new LevelTest(this));
            Manager.AddGameScreen(CameraTest.Key, new CameraTest(this));
            Manager.AddGameScreen(PathfindingTestBasic.Key, new PathfindingTestBasic(this));
            Manager.AddGameScreen(PathfindingTestAdv.Key, new PathfindingTestAdv(this));

            base.Initialize();
        }
        protected override void LoadContent()
        {
            //Load in global Resource list;
            CrystalCore.Resources.LoadData(this);

            Manager.LoadScreenManager();
        }
        protected override void Update(GameTime gameTime)
        {
            if (Manager != null)
            {
                if (Manager.InputController.IsNewKeyPress(Keys.F5))
                    Globals.DrawPrimitivesInDebugMode = !Globals.DrawPrimitivesInDebugMode;
            }

            Manager.Update(gameTime);

            base.Update(gameTime);
        }
        protected override void Draw(GameTime gameTime)
        {
            RasterizerState rs = new RasterizerState();
            rs.FillMode = GraphicsParams.DrawWireFrame ? FillMode.WireFrame : FillMode.Solid;
            rs.CullMode = GraphicsParams.EnableCulling ? CullMode.CullCounterClockwiseFace : CullMode.None;

            DepthStencilState ds = new DepthStencilState();
            ds.DepthBufferEnable = true;

            GraphicsDevice.RasterizerState = rs;
            GraphicsDevice.DepthStencilState = ds;
            GraphicsDevice.Clear(GraphicsParams.BufferColour);

            Manager.Draw(gameTime);

            base.Draw(gameTime);
        }
    }
}
